﻿using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace ExpressesClass.SfApi.Util
{
    internal class VerifyCodeUtil
    {
        public static string loadFile(string fileName)
        {
            string result;
            try
            {
                StreamReader streamReader = new StreamReader(fileName, Encoding.Default);
                StringBuilder stringBuilder = new StringBuilder();
                string text;
                while ((text = streamReader.ReadLine()) != null)
                {
                    stringBuilder.Append(text);
                }
                result = stringBuilder.ToString();
            }
            catch (Exception ex)
            {
                throw new IOException(ex.StackTrace);
            }
            return result;
        }
        public static string md5EncryptAndBase64(string str)
        {
            return encodeBase64(md5Encrypt(str));
        }
        private static byte[] md5Encrypt(string encryptStr)
        {
            byte[] result;
            try
            {
                MD5 mD = new MD5CryptoServiceProvider();
                result = mD.ComputeHash(Encoding.UTF8.GetBytes(encryptStr));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.StackTrace);
            }
            return result;
        }
        private static string encodeBase64(byte[] b)
        {
            return Convert.ToBase64String(b);
        }
    }
}
